//
//  BaseBarViewController.m
//  半糖
//
//  Created by RenShuang on 15/9/17.
//  Copyright (c) 2015年 shuang. All rights reserved.
//

#import "BaseBarViewController.h"
#import "BaseHeader.h"

@interface BaseBarViewController ()

{
    OneViewController *first;
    UINavigationController *firNav;
    FindViewController *find;
    UINavigationController *finNav;
    SearchViewController *search;
    UINavigationController *seaNav;
    MineViewController *mine;
    UINavigationController *minNav;
}
@property(nonatomic,retain)UIScrollView *launchScrollView;
@end

@implementation BaseBarViewController

- (void)dealloc
{
    [_launchScrollView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //首次启动的引导页
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        
        self.launchScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        self.launchScrollView.pagingEnabled = YES;
        self.launchScrollView.userInteractionEnabled = YES;
        self.launchScrollView.contentSize = CGSizeMake(SCREEN_WIDTH*3, 0);
        [self.view addSubview:self.launchScrollView];
        [_launchScrollView release];
        
        for (int i = 0; i < 3; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"引导%d.jpg",i]];
            imageView.userInteractionEnabled = YES;
            [self.launchScrollView addSubview:imageView];
            [imageView release];
            
            if (i == 2) {
                UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
                button.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                //button.backgroundColor = [UIColor yellowColor];
                //                [button setTitle:@"Let's GO!GO!GO!" forState:UIControlStateNormal];
                [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
                [imageView addSubview:button];
            }
        }
        
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
    }

    
    first = [[OneViewController alloc] init];
    firNav = [[UINavigationController alloc] initWithRootViewController:first];
    firNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"shouye.png"] tag:1000];
    
    find = [[FindViewController alloc] init];
    finNav = [[UINavigationController alloc] initWithRootViewController:find];
    finNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"faxian.png"] tag:2000];
    
    search = [[SearchViewController alloc] init];
    seaNav = [[UINavigationController alloc] initWithRootViewController:search];
    seaNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed:@"sousuo.png"] tag:3000];
    
    mine = [[MineViewController alloc] init];
    minNav = [[UINavigationController alloc] initWithRootViewController:mine];
    minNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"分类" image:[UIImage imageNamed:@"fenlei.png"] tag:4000];
    
    self.viewControllers = @[firNav,finNav,seaNav,minNav];
    self.tabBar.translucent = NO;
    self.tabBar.barTintColor = [UIColor whiteColor];
    self.tabBar.tintColor = [UIColor redColor];
    
    [first release];
    [find release];
    [search release];
    [mine release];
    
    [firNav release];
    [finNav release];
    [seaNav release];
    [minNav release];

    
    
}

- (void)click
{
    self.launchScrollView.alpha = 0;
    NSLog(@"lllll");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
